package com.freda.oa.flow.run.vo;

import java.util.Vector;

import com.freda.oa.flow.run.listener.itf.FlowBeforeListenerItf;
import com.freda.oa.flow.run.listener.itf.FlowCompletedListenerItf;
import com.freda.oa.flow.run.listener.itf.FlowOpenListenerItf;

/**
 * 总监听VO
 * 将所有监听统一管理。统一实例化
 * @author Rally
 *
 */
public class FlowCommonListenerVo {
	/**
	 * 所有before监听
	 */
	private Vector<FlowBeforeListenerItf> listBeforeListeners;
	/**
	 * 所有completed监听
	 */
	private Vector<FlowCompletedListenerItf> listCompletedListeners;
	/**
	 * 所有open监听
	 */
	private Vector<FlowOpenListenerItf> listOpenListeners;
	/**
	 * before监听字符串
	 */
	private String beforeStr;
	/**
	 * completed监听字符串
	 */
	private String completedStr;
	/**
	 * open监听字符串
	 */
	private String openStr;
	/**
	 * 构造方法
	 */
	public FlowCommonListenerVo()
	{
		
	}
	/**
	 * 是否含有Before监听
	 * @return
	 */
	public boolean isHasBLObject()
	{
		return this.listBeforeListeners.size() > 0;
	}
	/**
	 * 是否含有Completed监听
	 * @return
	 */
	public boolean isHasCLObject()
	{
		return this.listCompletedListeners.size() > 0;
	}
	/**
	 * 是否含有Open监听
	 * @return
	 */
	public boolean isHasOLObject()
	{
		return this.listOpenListeners.size() > 0;
	}
	/**
	 * before数量
	 * @return
	 */
	public int getBLObjectSize()
	{
		return this.listBeforeListeners.size();
	}
	/**
	 * completed数量
	 * @return
	 */
	public int getCLObjectSize()
	{
		return this.listCompletedListeners.size();
	}
	/**
	 * open数量
	 * @return
	 */
	public int getOLObjectSize()
	{
		return this.listOpenListeners.size();
	}
	/**
	 * @param beforeStr the beforeStr to set
	 */
	public void setBeforeStr(String beforeStr) {
		if(this.beforeStr != null && !this.beforeStr.equals(""))
		{
			this.beforeStr += "," + this.beforeStr;
		}
		else
		{
			this.beforeStr = beforeStr;			
		}
	}
	/**
	 * @param completedStr the completedStr to set
	 */
	public void setCompletedStr(String completedStr) {
		if(this.completedStr != null && !this.completedStr.equals(""))
		{
			this.completedStr += "," + this.completedStr;
		}
		else
		{
			this.completedStr = completedStr;
		}
	}
	/**
	 * @param openStr the openStr to set
	 */
	public void setOpenStr(String openStr) {
		if(this.openStr != null && !this.openStr.equals(""))
		{
			this.openStr += "," + this.openStr;
		}
		else
		{
			this.openStr = openStr;			
		}
	}
	/**
	 * @return the beforeStr
	 */
	public String getBeforeStr() {
		return beforeStr;
	}
	/**
	 * @return the completedStr
	 */
	public String getCompletedStr() {
		return completedStr;
	}
	/**
	 * @return the openStr
	 */
	public String getOpenStr() {
		return openStr;
	}
	/**
	 * @return the listBeforeListeners
	 */
	public Vector<FlowBeforeListenerItf> getListBeforeListeners() {
		return listBeforeListeners;
	}
	/**
	 * @return the listCompletedListeners
	 */
	public Vector<FlowCompletedListenerItf> getListCompletedListeners() {
		return listCompletedListeners;
	}
	/**
	 * @return the listOpenListeners
	 */
	public Vector<FlowOpenListenerItf> getListOpenListeners() {
		return listOpenListeners;
	}
	/**
	 * @param listBeforeListeners the listBeforeListeners to set
	 */
	public void setListBeforeListeners(
			Vector<FlowBeforeListenerItf> listBeforeListeners) {
		this.listBeforeListeners = listBeforeListeners;
	}
	/**
	 * @param listCompletedListeners the listCompletedListeners to set
	 */
	public void setListCompletedListeners(
			Vector<FlowCompletedListenerItf> listCompletedListeners) {
		this.listCompletedListeners = listCompletedListeners;
	}
	/**
	 * @param listOpenListeners the listOpenListeners to set
	 */
	public void setListOpenListeners(Vector<FlowOpenListenerItf> listOpenListeners) {
		this.listOpenListeners = listOpenListeners;
	}
	/**
	 * 实例化所有监听
	 * @param eventName
	 */
	public void createAllListeners(String eventName)
	{
		if(eventName.toLowerCase().indexOf("before") != -1)
		{
			try 
			{
				String[] before = this.beforeStr.split(",");
				
				for(int i=0;i<before.length;i++)
				{
					this.listBeforeListeners.add(before[i]!=null && !before[i].equals("") ? (FlowBeforeListenerItf)Class.forName(before[i]).newInstance() : null);
				}
			} catch (Exception e) 
			{
				e.printStackTrace();
				this.listBeforeListeners = null;
			}
		}
		else if(eventName.toLowerCase().indexOf("completed") != -1)
		{
			try 
			{
				String[] completed = this.completedStr.split(",");
				
				for(int i=0;i<completed.length;i++)
				{
					this.listCompletedListeners.add(completed[i] != null && !completed[i].equals("") ? (FlowCompletedListenerItf)Class.forName(completed[i]).newInstance() : null);
				}
			} catch (Exception e) 
			{
				e.printStackTrace();
				this.listCompletedListeners = null;
			}
		}
		else if(eventName.toLowerCase().indexOf("open") != -1)
		{
			try
			{
				String[] open = this.openStr.split(",");
				for(int i=0;i<open.length;i++)
				{
					this.listOpenListeners.add(open[i] != null && !open[i].equals("") ? (FlowOpenListenerItf)Class.forName(open[i]).newInstance() : null);
				}
			} catch(Exception e)
			{
				e.printStackTrace();
				this.listOpenListeners = null;
			}
		}
		
	}

}
